<?php

class cache_engine_file implements iCacheControllerBackend {
	
	public function __construct() {}
	
	public function load($key, $lifetime) {
		$filename = ENGINE_ROOT . '/cache/' . $key;
		
		if (!file_exists($filename)) {
			return false;
		}
		
		if (filemtime($filename) - time() < $lifetime) {
			return unserialize(file_get_contents($filename));
		} else {
			return false;
		}
	}
	
	public function save($key, $value, $lifetime) {
		file_put_contents(ENGINE_ROOT . '/cache/' . $key, serialize($value));
	}
	
	public function delete($key) {
		$filename = ENGINE_ROOT . '/cache/' . $key;
		
		if (file_exists($filename)) {
			unlink($filename);
		}
	}
	
}